package com.ruoyi.web.controller.depot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.depot.domain.OutboundOrder;
import com.ruoyi.depot.service.OutboundOrderService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单Controller
 * 
 * @author lxy
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/depot/outboundOrder")
public class OutboundOrderController extends BaseController
{
    @Autowired
    private OutboundOrderService outboundOrderService;

    /**
     * 查询出库单列表
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:query')")
    @GetMapping("/list")
    public TableDataInfo list(OutboundOrder outboundOrder)
    {
        startPage();
        List<OutboundOrder> list = outboundOrderService.selectOutboundOrderList(outboundOrder);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutboundOrder outboundOrder)
    {
        List<OutboundOrder> list = outboundOrderService.selectOutboundOrderList(outboundOrder);
        ExcelUtil<OutboundOrder> util = new ExcelUtil<OutboundOrder>(OutboundOrder.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:query')")
    @GetMapping(value = "/{outboundId}")
    public AjaxResult getInfo(@PathVariable("outboundId") Long outboundId)
    {
        return success(outboundOrderService.selectOutboundOrderByOutboundId(outboundId));
    }

    /**
     * 获取未出库的出库单记录数
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:list')")
    @GetMapping(value = "/count")
    public AjaxResult getUnpairedOutBoundStats()
    {
        return success(outboundOrderService.getUnpairedOutBoundStats());
    }

    /**
     * 新增出库单
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutboundOrder outboundOrder)
    {
        return toAjax(outboundOrderService.insertOutboundOrder(outboundOrder));
    }

    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutboundOrder outboundOrder)
    {
        return toAjax(outboundOrderService.updateOutboundOrder(outboundOrder));
    }

    /**
     * 确认出库
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:confirm')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/confirmOutboundOrder/{outboundId}")
    public AjaxResult handleConfirmOutbound(@PathVariable  Long outboundId)
    {
        return toAjax(outboundOrderService.handleConfirmOutbound(outboundId));
    }

    /**
     * 删除出库单
     */
    @PreAuthorize("@ss.hasPermi('depot:outboundOrder:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outboundIds}")
    public AjaxResult remove(@PathVariable Long[] outboundIds)
    {
        return toAjax(outboundOrderService.deleteOutboundOrderByOutboundIds(outboundIds));
    }
}
